package com.shxy.controller;

import com.shxy.common.entity.CustomResult;
import com.shxy.controller.ui.Option;
import com.shxy.entity.custom.CustomClazz;
import com.shxy.service.IBaseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 下拉列表选项查询
 */
@RequestMapping("/v1/select")
@RestController
public class ItemController {
    @Autowired
    private IBaseInfoService baseInfoService;

    /**
     * 获取学年列表
     * @return
     */
    @GetMapping("/years")
    public CustomResult getYears() {
        List<Option> years = baseInfoService.getYearsAll().stream().map(year -> Option.create(year, year)).collect(Collectors.toList());
        return new CustomResult(years);
    }

    /**
     * 获取学院列表
     * @return
     */
    @GetMapping("/colleges/year/{year}")
    public CustomResult getColleges(@PathVariable(name = "year")String year) {
        List<Option> colleges = baseInfoService.getCollegesAll(year).stream().map(college -> Option.create(String.valueOf(college.getId()), college.getName())).collect(Collectors.toList());
        return new CustomResult(colleges);
    }

    /**
     * 获取专业列表
     * @param collegeId
     * @return
     */
    @GetMapping("/majors/year/{year}")
    public CustomResult getMajors(@PathVariable(name = "year") String year,
                                  @RequestParam(defaultValue = "0") int collegeId) {
        List<Option> majors = baseInfoService.getMajors(year, collegeId).stream().map(major -> Option.create(String.valueOf(major.getId()), major.getName())).collect(Collectors.toList());
        return new CustomResult(majors);
    }

    /**
     * 获取班级列表
     * @param year
     * @param collegeId
     * @param majorId
     * @return
     */
    @GetMapping("/clazzes/year/{year}")
    public CustomResult getClazzes(@PathVariable(name = "year") String year,
                                   @RequestParam(defaultValue = "0") int collegeId,
                                   @RequestParam(defaultValue = "0") int majorId) {
        List<Option> clazzes = baseInfoService.getClazzList(year, collegeId, majorId).stream().map(clazz -> Option.create(String.valueOf(clazz.getId()), clazz.getName())).collect(Collectors.toList());
        return new CustomResult(clazzes);
    }
}
